<?php
  require_once('scripts/restrict_access.php');
  if ($identity->accessLevel>30){
	header('Location: AccessDenied.php');
	exit;
}
?> 
 <?php 
	       if (isset($_GET['id'])){
			   if ($_GET['id']!=0){
				   // List all contaners that are child of id
			   $sql = 'SELECT * FROM `containers` WHERE `parentId`= ? ORDER BY name';
			   $result = $dbRead->fetchAll($sql,$_GET['id']);
			   $size_of_result = sizeof($result); 
			   // List all items that are child of id
			   $sql = 'SELECT * FROM `items` WHERE `containerId`= ? ORDER BY position';
			   $items = $dbRead->fetchAll($sql,$_GET['id']);
			   $number_of_items = sizeof($items);
			   }else {
			   //We are listing a catalog. List only it's containers since there can be no items
			   $sql = 'SELECT * FROM `containers` WHERE `dbId`= ? AND `parentId`= 0 ORDER BY name';
			   $result = $dbRead->fetchAll($sql,$_GET['dbId']);
			   $size_of_result = sizeof($result);
			   $number_of_items = 0;
			   }
			   
		   } else{
			   //We are listing a catalog. List only it's containers since there can be no items
			   $sql = 'SELECT * FROM `containers` WHERE `dbId`= ? AND `parentId`= 0 ORDER BY name';
			   $result = $dbRead->fetchAll($sql,$_GET['dbId']);
			   $size_of_result = sizeof($result);
			   $number_of_items = 0;
		   }
 ?>
 <?php require_once('scripts/calculate_path.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Title      : Complimentary
Version    : 1.0
Released   : 20080409
Description: A two-column, fixed-width and lightweight template ideal for 1024x768 resolutions. Suitable for blogs and small websites.

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>BrowseCatalog</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="CSS/ComplementaryDefault.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo">
    <h1><a href="#">Find-it</a>
</h1></div>
<div id="menu">
  <ul>
    <li class="active"><a href="DBList.php">Catalogs</a></li>
    <li></li>
    
    <li><a href="AddContainerForm.php?dbId=<?php echo $_GET['dbId'];?>&amp;id=<?php echo (isset($_GET['id']) ? $_GET['id'] : 0);?>&amp;name=<?php echo $_GET['name'];?>">
        Add container </a></li>
        
    <li><a href="ManageLabels.php">Labels</a></li>
    <?php echo (isset($_GET['id']) ? '<li><a href="AddItemForm.php?dbId='.$_GET['dbId'].'&amp;id='.$_GET['id'].'&amp;name='.$_GET['name'].'">New Item</a></li>' : "") ?>
    <li><a href="Index.php?logout">Logout </a></li>
    </ul>
</div>
</div>
<!-- end header -->
<!-- start page -->
<div id="page">
  <!-- start content -->
  <div id="content">
    <div class="post">
      <p><br />
      </p>
      <div class="searchfield">
        <form method="get" action="SearchResults.php">
    <fieldset>
      <input name="searchtext" type="text" id="s" value="" />
      <input name="dbId" type="hidden" value="<?php echo $_GET['dbId'];?>" />
      <input type="submit" id="x" value="Search" />
      </fieldset>
  </form>
</div><br/>
<h1 class="title"><?php echo $_GET['name'];?></h1>
<div class="entry">
<!--Display captured error messages and warnings -->
        <p>
        <span class="warning">
         <?php require_once('scripts/msg_DBMain.php'); ?>        
        </span></p>
        
  <!--Display the path to the container -->      
        <?php echo $path ?>
        <p></p>
        
   <!--List of Containers -->
   <?php if ($size_of_result!=0){
	   require_once('listContainers.php');
   } ?>
   <!--List Items -->
   <?php if ($number_of_items!=0){
	   require_once('listItems.php');
   } ?>
   
      <!-- The bottomSpace div is for reserving space at the bottom for the footer -->
        <div class="bottomSpace">
          <p><br /><br />
          </p>
        </div>
      </div>
</div>
  </div>
  <!-- end content -->
  <!-- start sidebar --><!-- end sidebar -->
  <div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->
<!-- start footer -->
<div id="footer">
  <p id="legal">(c) 2012 Find-It. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.<br />
	</p>
</div>
<!-- end footer -->
</body>
</html>